﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;

namespace MX.Core.Caching
{
	public class Common
	{
		/// <summary>
		/// 检查数据是否为空
		/// </summary>
		/// <returns><c>true</c>, if value was checked, <c>false</c> otherwise.</returns>
		/// <param name="value">Value.</param>
		public static bool CheckValueNull (Object value)
		{  
			if (value is string) {
				return !string.IsNullOrEmpty (value as string);
			}
			if (value is IEnumerable)
				return GetCount (value as IEnumerable) != 0;
			else
				return (value != null); 
		}


		static	int GetCount (IEnumerable source)
		{
			if (source == null)
				return 0;
			if (source is ICollection) {
				return (source as ICollection).Count;
			} 
			int result = 0;
			IEnumerator enumerator = source.GetEnumerator ();
			while (enumerator.MoveNext ())
				result++; 
			return result;
		}
	}
}

